<template>
  <div>
    <nut-navbar
      class="my_nav"
      @on-click-back="back"
      @on-click-title="title"
      @on-click-more="more"
      :leftShow="false"
      :rightShow="true"
      >童家豪爵—用户管理系统</nut-navbar
    >
    <nut-elevator
      :dataArray="dataList"
      :showIndicator="true"
      :navHeight="40"
      :otherHeight="60"
      :initIndex="0"
      :hiddenTime="500"
    >
    </nut-elevator>
  </div>
</template>

<script>
import unit from "../../unit/unit.js";
export default {
  data() {
    return {
      tableData: [],
      dataList: [],
    };
  },
  // 获取用户信息
  created() {
    let id = "LXuao";
    this.$axios({
      method: "POST",
      url: "/api/finduser",
      data: {
        id: id,
      },
    }).then((res) => {
      // this.tableData = res.data.data;
      let templist = res.data.data;
      let flag = false; //设置一个flag标记。

      for (let i in templist) {
        for (let j in this.dataList) {
          if (
            unit.getPy(templist[i].username)[0].substr(0, 1) ==
            this.dataList[j].title
          ) {
            flag = true;
          }
        }
        if (flag == false) {
          this.dataList.push({
            title: unit.getPy(templist[i].username)[0].substr(0, 1),
            list: [],
          });
        } //循环结束。
        flag = false;
        // console.log(this.dataList);
        for (let j in this.dataList) {
          if (
            unit.getPy(templist[i].username)[0].substr(0, 1) ==
            this.dataList[j].title
          ) {
            this.dataList[j].list.push({
              name: templist[i].username,
              id: templist[i]._id,
            });
          }
        }
      }
      this.dataList.sort(function (x, y) {
        return x.title.charCodeAt() - y.title.charCodeAt();
      });
    });
  },
  methods: {
    back() {
      //   alert("header头部， 点击返回");
    },
    title() {
      //   alert("header头部， 点击title");
    },
    more() {
      //   alert("header头部， 点击更多");
      //   alert(getPy("张三"));
    },
  },
  components: {},
};
</script>

<style>
.my_nav {
  border-radius: 5px;
  background-color: skyblue;
  color: #fff;
  font-size: 12px;
  margin-bottom: 10px;
}
</style>
